﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <script type="text/javascript">
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null)
                return unescape(r[2]);
            return "error";
        }
        $(function () {
            var tabTitle, strHtml;
            var tabVal = getUrlParam("tab");
            if (tabVal != "error") {
                tabTitle = tabVal;
                var strSrc = getUrlParam("src");
                strHtml = '<iframe id="frmWorkArea" width="100%" height="95%" frameborder="0" scrolling="yes" src="' + strSrc + '"></iframe>';
            }
            else {
                var roleType = '@ViewBag.RoleType';
                if (roleType == "admin") {
                    tabTitle = "User Management";
                    strHtml = '<iframe id="frmWorkArea" width="100%" height="95%" frameborder="0" scrolling="yes" src="/User/Index"></iframe>';
                }
                else if (roleType == "customer")
                {
                    tabTitle = "Basic Profile";
                    strHtml = '<iframe id="frmWorkArea" width="100%" height="95%" frameborder="0" scrolling="yes" src="/User/MyProfile"></iframe>';
                }
                else {
                    tabTitle = "Advt Management";
                    strHtml = '<iframe id="frmWorkArea" width="100%" height="95%" frameborder="0" scrolling="yes" src="/AdvtAdmin/Index"></iframe>';
                }
            }
            openTab(tabTitle, strHtml);
            bindMenuClickEvent();
            $("tabContainer").tabs();
        });

        function openTab(tabTitle, strHtml) {            
            $('#tabContainer').tabs('add', {
                title: tabTitle,
                content: strHtml,
                iconCls: 'icon-save',
                closable: true
            });
        }

        function bindMenuDataAsync() {
            $.getJSON("", {}, function (data) {
                for (var i = 0; i < data.length; i++) {
                    //TODO: Need to add data support.
                }
            });
            bindMenuClickEvent();
        }

        function bindMenuClickEvent() {
            $(".easyui-linkbutton").click(function () {
                var src = $(this).attr("src");
                var tabTitle = $(this).text();
                //Navigate frame to link href.
                var strHtml = '<iframe id="frmWorkArea" width="100%" height="95%" frameborder="0" scrolling="yes" src="' + src + '"></iframe>';
                //Check if current tab has existed.
                var isExist = $("#tabContainer").tabs('exists', tabTitle);
                if (!isExist) {
                    $("#tabContainer").tabs('add', {
                        title: tabTitle,
                        content: strHtml,
                        iconCls: 'icon-save',
                        closable: true
                    });
                }
                else {
                    $('#tabContainer').tabs('select', tabTitle);
                }
            });
        }
    </script>
    <style type="text/css">
        .logout
        {
            background: url(images/logout_icon.png) left top no-repeat;
            height: 15px;
            padding-left: 20px;
            padding-bottom: 10px;
        }

        .username
        {
            background: url(images/user_icon.png) left top no-repeat;
            height: 15px;
            padding-left: 20px;
            padding-bottom: 10px;
        }
    </style>
</head>
<body class="easyui-layout">
    <input type="hidden" id="isAdmin"/>    
    
    <div data-options="region:'north',border:false" style="font-weight: bold; font-size: 18px; height: 120px; background: #f7f7f7; padding-top: 10px; border-top:3px solid #f66a0b">
        <div style="float:left; margin-left:20px"><a href="/"><img src="~/Images/logo.gif" height="100px"/></a></div>
        <div style="float:left; margin-left:70px;"><img src="~/Images/header-ad-admin.gif" /></div>

        <div style="float: right; padding-right: 60px; font-size: 11px; padding-top: 80px;">
            <a class="username" href="#">@ViewBag.LoginName</a>  |  
            <a class="logout" href="/AdminDefault/LogOff">Logout</a>
        </div>
    </div>
    
    <div data-options="region:'west',split:true,title:'Menu'" style="width: 170px;">
        @* menu container *@
        <div id="menuContainer" class="easyui-accordion" data-options="fit:true,border:false" style="text-align: center;">            

            @foreach (CashOrCard.Models.Menu menuItem in ViewBag.MenuList)
            {
                <div title="@menuItem.Text" @menuItem.IsDefault? "data-options='selected:true'": "">
                    @foreach (var subMenuItem in menuItem.SubMenus)
                    {
                        <p><a href="javascript:void(0)" src="@subMenuItem.NavLink" class="easyui-linkbutton" data-options="plain:true">@subMenuItem.Text</a></p>
                    }                    
                </div>
            }


        </div>
    </div>
    <div data-options="region:'south',border:false" style="height: 50px; background: #f7f7f7; padding: 10px 20px;border-bottom:3px solid #f66a0b; line-height:25px;">
        Copyright 2013. All rights reseved
    </div>
    <div data-options="region:'center',title:'Welcome'">
        @* tab container *@
        <div id="tabContainer" class="easyui-tabs" data-options="tools:'#tab-tools'" fit="true">
            @*  <div title="Home" style="padding: 10px">
                Message ddd
            </div>*@
        </div>
    </div>    
</body>
</html>
